package jastgen.generator;

import static jastgen.generator.Helper.*;

import java.io.PrintWriter;
import java.util.*;

import jastgen.CompileException;
import jastgen.nodes.ClassDef;
import jastgen.nodes.Module;

import static jastgen.generator.Generator.*;

class VisitorStubBodyGenerator implements BodyGenerator {

	private final List<String> visitReturnTypes;
	private final Module node;

	VisitorStubBodyGenerator(
			final List<String> visitReturnTypes,
			final Module node
		) throws CompileException {

		this.visitReturnTypes = visitReturnTypes;
		this.node = node;
	}

	public void generate(
			final PrintWriter out)
	{
		generateVisitorBody(out, node);
	}

	private void generateVisitorBody(
			final PrintWriter out,
			final Module node)
	{
		out.print("public abstract class VisitorStub");

		// VisitorImplとVisitorStubでほぼ共通
		// (違いはextendsまたはimplementsの行とスペースの数のみ)
		// NodeReplacerのように「<」の直後で改行し共通化するか?
		printTypeParams(out, visitReturnTypes, "                                  ");
		out.println();
		out.print("	extends VisitorImpl");
		printTypeParams(out, visitReturnTypes, "	                    ");
		out.println();
		out.print("{");

		for(final ClassDef c : node.getClassDefs()) {
			printMethod(out, c, retTy(c));
		}

		out.println("}");
	}
}
